﻿Ext.define('app.system.project_role.Index',
{
    extend: 'Ext.grid.Panel',
    border: true,
    //title: '项目角色',
    // tbar: [],
    //controller: 'substance',
    //viewModel: {
    //    type: 'compoundModel'
    //},
    //requires: ['app.system.substance.SubstanceController'],
    viewConfig: {
        enableTextSelection: true //可以复制单元格文字
    },
    multiColumnSort: true,
    forceFit: true,
    initComponent: function () {
        var me = this;
        me.items = [];
        me.tbar = [
            {
                text: localize('Add'), iconCls: "add", handler: function () {
                    var win = Ext.create("app.system.project_role.Edit", { title: localize('AddRole') });
                    win.on("savesuccess", function () {
                        me.store.load();
                        win.close();
                    });
                    win.show();
                }
            }
        ];
        me.store = Ext.create("app.ux.PrmStore", { url: '/api/services/app/projectRole/GetAll' });
        me.callParent(arguments);
    },
    columns: [
        {
            xtype: 'actioncolumn',
            width: 35,
            header: localize('Operating'),
            items: [
            {
                iconCls: 'edit',
                tooltip: '编辑',
                handler: function (grid, rowIndex, colIndex) {
                    var record = grid.store.getAt(rowIndex);
                    var win = Ext.create("app.system.project_role.Edit", { title: '项目角色编辑', recordData: record });
                    win.on("savesuccess", function () {
                        grid.store.load();
                        win.close();
                    });
                    win.show();
                },
                getClass: function (v, meta, rec) {
                    if (rec.data.isReserved) {
                        return 'x-hidden'
                    } else {
                        return 'edit'
                    }
                }
            },
            {
                icon: '/Content/images/delete.gif',
                tooltip: '删除',
                handler: function (grid, rowIndex, colIndex) {
                    var record = grid.store.getAt(rowIndex);
                    Ext.Msg.confirm('系统提示', '确定要删除项目角色吗？', function (btn) {
                        if (btn == 'yes') {
                            App.AjaxDelete('/api/services/app/projectRole/Remove?projectRoleId=' + record.data.id, function (data)
                            {
                                grid.store.removeAt(rowIndex);
                            });
                        }
                    });
                },
                getClass: function (v, meta, rec) {
                    if (rec.data.isReserved) {
                        return 'x-hidden'
                    } else {
                        return 'edit'
                    }
                }
            }
            ]
        },
        { header: localize('RoleName'), dataIndex: 'roleName' },
        { header: localize('Sortfactor'), dataIndex: 'sortfactor' },
        //{ header: "内置关联角色", dataIndex: 'internalRole' },
        {
            header: localize('IsReserved'), dataIndex: 'isReserved', renderer: function (value, p, record) {
                return value ? "是" : "否";
            }
        },
        //{
        //    header: localize('IsHumanWork'), dataIndex: 'isHumanWork', renderer: function (value, p, record) {
        //        return value ? "是" : "否";
        //    }
        //},
        { header: localize('Description'), dataIndex: 'description' },
    ]
});
